package com.wutuo.wtservice.provider.dao;

import com.wutuo.wtservice.api.request.ListWtTypeRequest;
import com.wutuo.wtservice.api.request.WtTypeRequest;
import org.apache.ibatis.jdbc.SqlBuilder;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * 标签关系表 dao sql 层
 *
 * @author lvh
 * @version 1.0
 */
public class WtTypeSqlProvider extends BaseWtTypeSqlProvider {
    public String lisForPage(ListWtTypeRequest request) {
        BEGIN();
        getSelected();
        FROM("wt_type a ");

        SqlBuilder.WHERE(" a.del_flag =  #{delFlag,jdbcType=CHAR}");
        StringBuilder sql = new StringBuilder(SqlBuilder.SQL());

        if (request.getPage() != null && request.getSize() != null) {
            sql.append(" limit #{index,jdbcType=INTEGER} ,  #{size,jdbcType=INTEGER} ");
        }

        return sql.toString();
    }

    public String list(WtTypeRequest request) {
        BEGIN();
        getSelected();
        FROM("wt_type a");
        geCommonJoin(request);
        SqlBuilder.WHERE(" a.del_flag =  #{delFlag,jdbcType=CHAR}");
        StringBuilder sql = new StringBuilder(SqlBuilder.SQL());
        return sql.toString();
    }

    public void getSelected() {
        SELECT(
            "a.id,a.type_image as typeImage,a.name as name,a.type_describe as typeDescribe,create_by as createBy,create_date as createDate,update_by as updateBy,update_date as updateDate,remarks as remarks,del_flag as delFlag");
    }

    public void geCommonJoin(WtTypeRequest request) {
        if (request.getInitFlag() != null) {
            SqlBuilder.WHERE("a.id BETWEEN 0 AND 5");
        }
    }

}